/**
 * @copyright Copyright (c) 2025 CSG Digital Grid Technology (Guangdong) Co., Ltd.
 * @author Chen Yongjie
 */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <CUnit/Basic.h>

#include "test_cJSON.h"

int main() {
    // 初始化 CUnit 测试套件
    if (CUE_SUCCESS != CU_initialize_registry()) {
        return CU_get_error();
    }
    CU_pSuite pSuite1 = CU_add_suite("suite_1", NULL, NULL);
    CU_pSuite pSuite2 = CU_add_suite("suite_2", NULL, NULL);
    if (NULL == pSuite1 || NULL == pSuite2) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    // 添加测试用例
    if (((NULL == CU_add_test(pSuite1, "test_cJSON_GetStringValue_valid", test_cJSON_GetStringValue_valid)) ||
        (NULL == CU_add_test(pSuite1, "test_cJSON_GetStringValue_invalid_type", test_cJSON_GetStringValue_invalid_type)) ||
        (NULL == CU_add_test(pSuite1, "test_cJSON_GetNumberValue_invalid_type", test_cJSON_GetNumberValue_invalid_type)) ||
        (NULL == CU_add_test(pSuite1, "test_cJSON_GetNumberValue_null", test_cJSON_GetNumberValue_null))
        ) ) 
    {
        CU_cleanup_registry();
        return CU_get_error();
    }
    
   if ((NULL == CU_add_test(pSuite1, "test_cJSON_GetStringValue_null", test_cJSON_GetStringValue_null)) ) 
    {
        CU_cleanup_registry();
        return CU_get_error();
    }
 

    // 运行测试用例--测试时用
    //CU_basic_set_mode(CU_BRM_VERBOSE);
    //CU_basic_run_tests();

    // 设置自动化模式的输出文件名
    CU_set_output_filename("CUnit");

    // 运行自动化测试
    CU_automated_run_tests();

    CU_cleanup_registry();
    return CU_get_error();
}